package com.mrtaohuan.data;

import lombok.extern.java.Log;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import com.googlecode.objectify.ObjectifyFactory;
import com.mrtaohuan.data.entity.User;

@Singleton
@Log
public class OfyFactory extends ObjectifyFactory {

	@Inject
	private static Injector injector;

	public OfyFactory() {
		long time = System.currentTimeMillis();

		// register entity
		register(User.class);

		long millis = System.currentTimeMillis() - time;
		log.info("Registration took " + millis + " millis");
	}

	@Override
	public <T> T construct(Class<T> type) {
		return injector.getInstance(type);
	}

	@Override
	public Ofy begin() {
		return new Ofy(this);
	}
}
